package ch07_GUI编程;

import javax.swing.*;
import java.awt.*;
import java.util.Hashtable;

public class JSliderDemo {
	public static void main(String[] args) {
		BaseFrame f = new BaseFrame("JSlider Demo");
		f.setLayout(new GridLayout(3,1,0,5));

		JSlider s1 = new JSlider();
		s1.setExtent(20);
		s1.setValue(90);

		JSlider s2 = new JSlider(SwingConstants.HORIZONTAL);
		s2.setMinimum(-10);
		s2.setMaximum(20);
		s2.setValue(-5);
		s2.setMajorTickSpacing(10);
		s2.setMinorTickSpacing(1);
		s2.setPaintTicks(true);
		s2.setPaintLabels(true);

		JSlider s3 = new JSlider(SwingConstants.HORIZONTAL,0,10,5);
		s3.setMajorTickSpacing(5);
		s3.setPaintTicks(true);
		s3.setPaintLabels(true);
		s3.setSnapToTicks(true);

		Hashtable labs = new Hashtable();
		int min = s3.getMinimum();
		int max = s3.getMaximum();
		labs.put(min, new JLabel("最长续航"));
		labs.put((max-min)/2, new JLabel("平衡"));
		labs.put(max, new JLabel("最佳性能"));

		s3.setLabelTable(labs);

		f.add(s1);
		f.add(s2);
		f.add(s3);
		f.showMe();
	}
}
